﻿using Mono.Cecil;
using Mono.Cecil.Cil;

namespace Cil.Ast;

public sealed class SizeofExpression : SingleInstructionExpression
{
	public SizeofExpression(Context context, Instruction position)
		: base(context, position)
	{
		// base class
		ReturnType = Context.MakeRef<int>();
		WritesStack = 1;
		ReadsStack = 0;
		TypeReference = position.Operand as TypeReference;
		Nodes = new FixedList<Expression>();
	}

	TypeReference TypeReference { get; set; }

	public override string ToString()
	{
		return string.Format("sizeof({0})", TypeReference);
	}
}

public static partial class IlAst
{
	public static SizeofExpression Sizeof(Context context, Instruction position)
	{
		return new SizeofExpression(context, position);
	}
}